package com.ruoyi.wlxz.controller;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.poi.ExcelUtilStudent;
import com.ruoyi.wlxz.domain.WxzStudentPublic;
import com.ruoyi.wlxz.domain.dto.StudentSupplement;
import com.ruoyi.wlxz.domain.vo.IfActivity;
import com.ruoyi.wlxz.service.IWxzStudentPublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * 学生活动报名Controller
 *
 * @author 张浩
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/wlxz/stupublic")
public class WxzStudentPublicController extends BaseController {
    @Autowired
    private IWxzStudentPublicService wxzStudentPublicService;
    /**
     * 查询学生活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('wlxz:stupublic:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxzStudentPublic wxzStudentPublic) {
        startPage();
        List<WxzStudentPublic> list = wxzStudentPublicService.selectWxzStudentPublicList(wxzStudentPublic);
        return getDataTable(list);
    }
    /**
     * 导出学生活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('wlxz:stupublic:export')")
    @Log(title = "学生活动报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxzStudentPublic wxzStudentPublic) {
        List<WxzStudentPublic> list = wxzStudentPublicService.selectWxzStudentPublicList(wxzStudentPublic);
        ExcelUtil<WxzStudentPublic> util = new ExcelUtil<WxzStudentPublic>(WxzStudentPublic.class);
        util.exportExcel(response, list, "学生活动报名数据");
    }
    /**
     * 导出学生补录名单
     */
    @Log(title = "学分补录名单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSupplement")
    public void exportSupplement(HttpServletResponse response, Integer activityId) {
        //根据id查询报名的学生和学分补录信息
        List<StudentSupplement> list = wxzStudentPublicService.selectStudentSupplementList(activityId);
        ExcelUtilStudent<StudentSupplement> util = new ExcelUtilStudent<StudentSupplement>(StudentSupplement.class);
        util.exportExcel(response, list, "学生活动报名数据");
    }
    /**
     * 获取学生活动报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('wlxz:stupublic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wxzStudentPublicService.selectWxzStudentPublicById(id));
    }
    /**
     * 根据活动id和学生学号查询学生活动报名信息
     */
    @PreAuthorize("@ss.hasPermi('wlxz:stupublic:query')")
    @GetMapping(value = "/query")
    public AjaxResult getInfoByActivityIdAndStudentNumber(WxzStudentPublic wxzStudentPublic) {
        return success(wxzStudentPublicService.selectWxzStudentPublicByActivityIdAndStudentNumber(wxzStudentPublic));
    }
    /**
     * 新增学生活动报名
     */
    @PreAuthorize("@ss.hasPermi('wlxz:stupublic:add')")
    @Log(title = "学生活动报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IfActivity ifActivity) {
        return toAjax(wxzStudentPublicService.insertWxzStudentPublic(ifActivity));
    }
    /**
     * 修改学生活动报名
     */
    @PreAuthorize("@ss.hasPermi('wlxz:stupublic:edit')")
    @Log(title = "学生活动报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxzStudentPublic wxzStudentPublic) {
        return toAjax(wxzStudentPublicService.updateWxzStudentPublic(wxzStudentPublic));
    }
    /**
     * 删除学生活动报名
     */
    @PreAuthorize("@ss.hasPermi('wlxz:stupublic:remove')")
    @Log(title = "学生活动报名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wxzStudentPublicService.deleteWxzStudentPublicByIds(ids));
    }
}
